﻿using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Linq;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    public partial class ITXEXRPT
    { 
         
        private void TSTEK05(DataSet db)  
        {
            try
            {
                DataTable tbEKKOPF = dsSource.Tables["EKKOPF"];
                DataRow dwEKKOPF = tbEKKOPF.Rows[0];
                string src = "",CURRENCY = "";

                src = dwEKKOPF["ORDNO"].ToString();
                exAgent.SetCellValue(4, 34, src);
                src = dwEKKOPF["CUSTOMER"].ToString().Trim();
                exAgent.SetCellValue(6, 5, Helper.GetGB2312Value(src));
                src = dwEKKOPF["SUPP"].ToString().Trim();
                exAgent.SetCellValue(6, 19, Helper.GetGB2312Value(src));
                src = dwEKKOPF["DAT"].ToString().Trim();
                exAgent.SetCellValue(6, 34, src);
                src = Helper.GetGB2312Value(dwEKKOPF["INVNAME"].ToString().Trim()) + System.Environment.NewLine + Helper.GetGB2312Value(dwEKKOPF["INVADR"].ToString().Trim());
                exAgent.SetCellValue(9, 1, src);
                src = Helper.GetGB2312Value(dwEKKOPF["DELNAME"].ToString().Trim()) + System.Environment.NewLine + Helper.GetGB2312Value(dwEKKOPF["DELADR"].ToString().Trim());
                exAgent.SetCellValue(9, 20, src);
                src = dwEKKOPF["DELT"].ToString().Trim();
                exAgent.SetCellValue(172, 7, Helper.GetGB2312Value(src));
                src = dwEKKOPF["PAYBEZ"].ToString().Trim();
                exAgent.SetCellValue(171, 7, Helper.GetGB2312Value(src));
                src = dwEKKOPF["TRU"].ToString().Trim();
                exAgent.SetCellValue(172, 25, Helper.GetGB2312Value(src));
                src = dwEKKOPF["TOLERANCE"].ToString().Trim();
                exAgent.SetCellValue(182, 12, Helper.GetGB2312Value(src));
                src = dwEKKOPF["REMARK"].ToString().Trim();
                exAgent.SetCellValue(183, 12, Helper.GetGB2312Value(src));
                CURRENCY = dwEKKOPF["CURRENCY"].ToString().Trim();
                exAgent.SetCellValue(13, 29, "Total value (" + Helper.GetGB2312Value(CURRENCY) + ")");

                DataTable tbEKPOS = dsSource.Tables["EKPOS"];
                int x = 14;
                string wid = "", totwid = "", gm = "", sqm = "",comp ="";
                foreach (DataRow dwEKPOS in tbEKPOS.Rows)
                {
                    src = dwEKPOS["POS"].ToString().Trim();
                    exAgent.SetCellValue(x, 1, System.Convert.ToInt64(src));
                    src = dwEKPOS["ART"].ToString().Trim() + System.Environment.NewLine + dwEKPOS["ARTDES"].ToString().Trim();
                    exAgent.SetCellValue(x, 3, Helper.GetGB2312Value(src));
                    src = dwEKPOS["COLOR"].ToString().Trim();
                    exAgent.SetCellValue(x, 11, Helper.GetGB2312Value(src));
                    src = dwEKPOS["QTY"].ToString().Trim();
                    exAgent.SetCellValue(x, 15, System.Convert.ToDouble(src));
                    src = dwEKPOS["UNIT"].ToString().Trim();
                    exAgent.SetCellValue(x, 18, Helper.GetGB2312Value(src));
                    exAgent.SetCellValue(x, 20, dwEKPOS["PRICE"].ToString().Trim() + " " + Helper.GetGB2312Value(CURRENCY).ToLower());
                    src = dwEKPOS["SUR"].ToString().Trim();
                    exAgent.SetCellValue(x, 23, System.Convert.ToDouble(src));
                    src = dwEKPOS["DIS"].ToString().Trim();
                    exAgent.SetCellValue(x, 26, System.Convert.ToDouble(src));
                    src = dwEKPOS["SDAT"].ToString().Trim();
                    exAgent.SetCellValue(x, 33, src);
                    src = dwEKPOS["BDAT"].ToString().Trim();
                    exAgent.SetCellValue(x, 37, src);
                    src = dwEKPOS["VALUE"].ToString().Trim();
                    exAgent.SetCellValue(x, 29, System.Convert.ToDouble(src));
                    
                    wid = dwEKPOS["WID"].ToString().Trim();
                    totwid = dwEKPOS["TOTWID"].ToString().Trim();
                    gm = dwEKPOS["GM"].ToString().Trim();
                    sqm = dwEKPOS["SQM"].ToString().Trim();
                    comp = Helper.GetGB2312Value(dwEKPOS["COMP"].ToString().Trim());
                    src = "Composition:" + comp; 
                    exAgent.SetCellValue(x+1, 3, src);
                    src = "";
                    if (totwid != "0")
                        {
                            src = src + "Total width:" + totwid + "cm  ";
                        }
                        if (wid != "0")
                        {
                            src = src + "Cuttable:" + wid + "cm     ";
                        }
                        if (gm != "0")
                        {
                            src = src + "Weigth:" + gm + "g/m  " + sqm + "g/sqm ";
                        }                    
                    exAgent.SetCellValue(x+2, 3, src);
                    x = x + 3;

                }
                
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);

            }            
        }
               
    }
}
